package org.blankhole.model;

import java.io.Serializable;
import java.util.Date;

/**
 * Model: Class <code>Model</code> is the root of the model hierarchy. Every
 * class has <code>Model</code> as a superclass. All models, implement the
 * methods of this class.
 * 
 * @author Wenlong Meng(wenlong.meng@gmail.com)
 * @version 1.0 at 2012/07/30
 * @since 1.0
 */
public class Model implements Serializable{

	//local variables
	/**
	 * id: primary key
	 */
	protected int id = NEW_ID;
	/**
	 * the create-time of model
	 */
	protected Date createDate;
	/**
	 * the last-update-time of model
	 */
	protected Date updateDate;
	/**
	 * the version of model
	 */
	protected int version = 0;
	/**
	 * new id: is new
	 */
	private static final int NEW_ID = -1;
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = -7620102976541129125L;
	
	//Setter and Getter
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	/**
	 * @return the createDate
	 */
	public Date getCreateDate() {
		return createDate;
	}
	/**
	 * @param createDate the createDate to set
	 */
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	
	/**
	 * @return the updateDate
	 */
	public Date getUpdateDate() {
		return updateDate;
	}
	/**
	 * @param updateDate the updateDate to set
	 */
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	
	/**
	 * @return the version
	 */
	public int getVersion() {
		return version;
	}
	/**
	 * @param version the version to set
	 */
	public void setVersion(int version) {
		this.version = version;
	}
	
	//Logic
	/**
     * Returns <tt>true</tt> if this model is new.
     *
     * @return <tt>true</tt> if this model is new
     */
	public boolean isNew(){
		return this.id == NEW_ID;
	}
	
	//toString
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Model [id=" + id + ", createDate=" + createDate
				+ ", updateDate=" + updateDate + ", version=" + version + "]";
	}
	
}
